/**
 *
 * Copyright 2016-present reading
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import React from 'react';
import { Platform } from 'react-native';
import { Provider } from 'react-redux';
import configureStore from './store/configure-store';
import rootSaga from './sagas/index';
import App from './containers/app';
import SafeAreaView from 'react-native-safe-area-view'

import {
  DeviceEventEmitter,
} from 'react-native';
import AliyunPush from 'react-native-aliyun-push';

import { getDeviceInfo } from './utils/DeviceInfo';

const store = configureStore();

console.disableYellowBox = true;

// run root saga
store.runSaga(rootSaga);

const Root = () => (
  <Provider store={store}>
    { Platform.os === 'ios' &&
      ( 
        <SafeAreaView>
          <App />
        </SafeAreaView>
      ) 
      ||
      <App />
    }
  </Provider>
);

class RootComponent extends React.Component {
  componentDidMount() {
    // AliyunPush.getDeviceId()
    // .then((deviceId)=>{
    //     console.log("AliyunPush deviceId:"+deviceId);
    // })
    // .catch((error)=>{
    //     console.log("getDeviceId() failed");
    // });

    // const deviceInfo = getDeviceInfo();
    // console.log(deviceInfo, 'deviceInfo');
  }

  componentWillUnmount() {
  }


  onMessage(e){
    // alert("Message Received. Title:" + e.title + ", Content:" + e.content);
    console.log("root Notification Message Received. Title:", e);
  }
  onNotification(e){
    // alert("Notification Received.Title:" + e.title + ", Content:" + e.content);
    console.log("root Notification Received.Title:" + e.title + ", Content:" + e.body);
  }
  onNotificationOpened(e) {
    // alert("Notification Clicked", e);
    console.log("root Notification Clicked", e)
  }
  onNotificationRemoved(e) {
    alert("root Notification removed");
  }

  render = () => Root()
}
export default RootComponent;
